using System.Collections.Generic;
using UI.Inspector;
using UnityEngine;
using UnityEngine.UIElements;

public class GameObjectInspector : BaseInspector
{
    public Dictionary<string, VisualElement> typeDic = new Dictionary<string, VisualElement>();
    private Label _name;
    private GameObject selectGo;

    public GameObjectInspector(VisualElement inspector, Transform _ransform) : base(_ransform, inspector, "GameObject")
    {
        _name = inspector?.Q<Label>("name");
        BaseUI();
        TransforUI();
    }

    private Toggle _toggle;

    void BaseUI()
    {
        var tfUI = uiElement?.Q<VisualElement>("base");
        _toggle = tfUI?.Q<Toggle>("active");
        _toggle.RegisterCallback<ChangeEvent<bool>>(e =>
        {
            // e.newValue;
            selectGo.SetActive(e.newValue);
        });
        tfUI?.Q<Toggle>("static").RegisterCallback<ChangeEvent<bool>>(e =>
        {
            // e.newValue;
            // selectGo.isStatic(e.newValue);
        });
    }

    private Vector3Field position;
    private Vector3Field rotation;
    private Vector3Field scale;

    void TransforUI()
    {
        var tfUI = uiElement?.Q<VisualElement>("transform");
        position = tfUI?.Q<Vector3Field>("position");
        rotation = tfUI?.Q<Vector3Field>("rotation");
        scale = tfUI?.Q<Vector3Field>("scale");
        
        position.RegisterCallback<ChangeEvent<Vector3>>((v3) =>
        {
            selectGo.transform.position = v3.newValue;
        });
        
        rotation.RegisterCallback<ChangeEvent<Vector3>>((v3) =>
        {
            selectGo.transform.eulerAngles = v3.newValue;
        });
        
        scale.RegisterCallback<ChangeEvent<Vector3>>((v3) =>
        {
            selectGo.transform.localScale = v3.newValue;
        });
    }

    public override void Ref(GameObject go)
    {
        selectGo = go;
        _name.text = go.name;
        _name.text = go.name;
        position.value = go.transform.position;
        rotation.value = go.transform.eulerAngles;
        scale.value = go.transform.localScale;
        _toggle.value = go.activeSelf;
    }
}